home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / uucp-104.lha / uucp-1.04 / trans.h < prev    next >
C/C++ Source or Header  |  1993-02-13  |  10KB  |  269 lines

  1. /* trans.h
  2.    Header file for file and command transfer routines.
  3.  
  4.    Copyright (C) 1992 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
  24.    */
  25.  
  26. /* The maximum possible number of channels.  */
  27. #define IMAX_CHAN (16)
  28.  
  29. /* The ifeatures field of the sdaemon structure is an or of the
  30.    following values.  These values are sent during the uucico
  31.    handshake, and MUST NOT CHANGE.  */
  32.  
  33. /* File size negotiation.  */
  34. #define FEATURE_SIZES (01)
  35.  
  36. /* File transfer restart.  */
  37. #define FEATURE_RESTART (02)
  38.  
  39. /* The E (execute) command.  */
  40. #define FEATURE_EXEC (04)
  41.  
  42. /* Version 1.03: requires decimal size in S and R command.  Needless
  43.    to say, this should not be used by any new programs.  */
  44. #define FEATURE_V103 (010)
  45.  
  46. /* SVR4 UUCP: expects dummy string between notify field and size field
  47.    in send command.  There is probably some meaning to this string,
  48.    but I don't know what it is.  If I ever find out, this flag will
  49.    still be used to indicate it.  */
  50. #define FEATURE_SVR4 (020)
  51.  
  52. /* This structure is used to hold information concerning the
  53.    communication link established with the remote system.  */
  54.  
  55. struct sdaemon
  56. {
  57.   /* Global uuconf pointer.  */
  58.   pointer puuconf;
  59.   /* Remote system information.  */
  60.   const struct uuconf_system *qsys;
  61.   /* Local name being used.  */
  62.   const char *zlocalname;
  63.   /* Connection structure.  */
  64.   struct sconnection *qconn;
  65.   /* Protocol being used.  */
  66.   const struct sprotocol *qproto;
  67.   /* The largest file size permitted for a local request.  */
  68.   long clocal_size;
  69.   /* The largest file size permitted for a remote request.  */
  70.   long cremote_size;
  71.   /* The largest file size that may ever be transferred.  */
  72.   long cmax_ever;
  73.   /* The remote system ulimit.  */
  74.   long cmax_receive;
  75.   /* Features supported by the remote side.  */
  76.   int ifeatures;
  77.   /* TRUE if we should request the remote side to hang up.  */
  78.   boolean frequest_hangup;
  79.   /* TRUE if the remote side requested a hangup.  */
  80.   boolean fhangup_requested;
  81.   /* TRUE if we are hanging up.  */
  82.   boolean fhangup;
  83.   /* TRUE if the local system is currently the master.  */
  84.   boolean fmaster;
  85.   /* TRUE if the local system placed the call.  */
  86.   boolean fcaller;
  87.   /* UUCONF_RELIABLE_* flags for the connection.  */
  88.   int ireliable;
  89.   /* If fcaller is FALSE, the lowest grade which may be transferred
  90.      during this call.  */
  91.   char bgrade;
  92. };
  93.  
  94. /* This structure is used to hold a file or command transfer which is
  95.    in progress.  */
  96.  
  97. struct stransfer
  98. {
  99.   /* Next file transfer in queue.  */
  100.   struct stransfer *qnext;
  101.   /* Previous file transfer in queue.  */
  102.   struct stransfer *qprev;
  103.   /* Points to the queue this structure is on.  */
  104.   struct stransfer **pqqueue;
  105.   /* The function to call to send some data.  */
  106.   boolean (*psendfn) P((struct stransfer *qtrans, struct sdaemon *qdaemon));
  107.   /* The function to call when data is received.  */
  108.   boolean (*precfn) P((struct stransfer *qtrans, struct sdaemon *qdaemon,
  109.                const char *zdata, size_t cdata));
  110.   /* Type specific information.   */
  111.   pointer pinfo;
  112.   /* TRUE if we are sending the file e (this is used to avoid a call
  113.      to psendfn).  */
  114.   boolean fsendfile;
  115.   /* TRUE if we are receiving the file e (this is used to avoid a call
  116.      to precfn).  */
  117.   boolean frecfile;
  118.   /* The file to read or write.  */
  119.   openfile_t e;
  120.   /* The position we are at in the file.  */
  121.   long ipos;
  122.   /* TRUE if we are waiting for a command string.  */
  123.   boolean fcmd;
  124.   /* The command string we have so far.  */
  125.   char *zcmd;
  126.   /* The length of the command string we have so far.  */
  127.   size_t ccmd;
  128.   /* Local destination number.  */
  129.   int ilocal;
  130.   /* Remote destination number.  */
  131.   int iremote;
  132.   /* The command.  */
  133.   struct scmd s;
  134.   /* A message to log when work starts.  */
  135.   char *zlog;
  136.   /* The process time; imicros can be negative.  */
  137.   long isecs;
  138.   long imicros;
  139.   /* Number of bytes sent or received.  */
  140.   long cbytes;
  141. };
  142.  
  143. /* Reasons that a file transfer might fail.  */
  144.  
  145. enum tfailure
  146. {
  147.   /* No failure.  */
  148.   FAILURE_NONE,
  149.   /* No permission for operation.  */
  150.   FAILURE_PERM,
  151.   /* Can't open necessary file.  */
  152.   FAILURE_OPEN,
  153.   /* Not enough space to receive file.  */
  154.   FAILURE_SIZE,
  155.   /* File was received in a previous conversation.  */
  156.   FAILURE_RECEIVED
  157. };
  158.  
  159. /* The main loop which talks to the remote system, passing transfer
  160.    requests and file back and forth.  */
  161. extern boolean floop P((struct sdaemon *qdaemon));
  162.  
  163. /* Allocate a new transfer structure.  */
  164. extern struct stransfer *qtransalc P((struct scmd *qcmd));
  165.  
  166. /* Free a transfer structure.  */
  167. extern void utransfree P((struct stransfer *qtrans));
  168.  
  169. /* Queue up local requests.  If pfany is not NULL, this sets *pfany to
  170.    TRUE if there are, in fact, any local requests which can be done at
  171.    this point.  */
  172. extern boolean fqueue P((struct sdaemon *qdaemon, boolean *pfany));
  173.  
  174. /* Clear away any queued requests.  This may be called more than once
  175.    at the end of a call.  */
  176. extern void uclear_queue P((struct sdaemon *qdaemon));
  177.  
  178. /* Queue a new transfer request made by the local system.  */
  179. extern boolean fqueue_local P((struct sdaemon *qdaemon,
  180.                    struct stransfer *qtrans));
  181.  
  182. /* Queue a new transfer request made by the remote system.  */
  183. extern boolean fqueue_remote P((struct sdaemon *qdaemon,
  184.                 struct stransfer *qtrans));
  185.  
  186. /* Queue a transfer request which wants to send something.  */
  187. extern boolean fqueue_send P((struct sdaemon *qdaemon,
  188.                   struct stransfer *qtrans));
  189.  
  190. /* Queue a transfer request which wants to receiving something.  */
  191. extern boolean fqueue_receive P((struct sdaemon *qdaemon,
  192.                  struct stransfer *qtrans));
  193.  
  194. /* Prepare to send a file by local or remote request.  */
  195. extern boolean flocal_send_file_init P((struct sdaemon *qdaemon,
  196.                     struct scmd *qcmd));
  197. extern boolean fremote_send_file_init P((struct sdaemon *qdaemon,
  198.                      struct scmd *qcmd,
  199.                      int iremote));
  200.  
  201. /* Prepare to receive a file by local or remote request.  */
  202. extern boolean flocal_rec_file_init P((struct sdaemon *qdaemon,
  203.                        struct scmd *qcmd));
  204. extern boolean fremote_rec_file_init P((struct sdaemon *qdaemon,
  205.                     struct scmd *qcmd,
  206.                     int iremote));
  207.  
  208. /* Prepare to request work by local or remote request.  */
  209. extern boolean flocal_xcmd_init P((struct sdaemon *qdaemon,
  210.                    struct scmd *qcmd));
  211. extern boolean fremote_xcmd_init P((struct sdaemon *qdaemon,
  212.                     struct scmd *qcmd,
  213.                     int iremote));
  214.  
  215. /* We have lost the connection; record any in progress file transfers
  216.    in the statistics file and discard any temporary files.  */
  217. extern void ufailed P((struct sdaemon *qdaemon));
  218.  
  219. /* Check that there is enough disk space for a file receive.  Return
  220.    FALSE if there is not.  */
  221. extern boolean frec_check_free P((struct stransfer *qtrans,
  222.                   long cfree_space));
  223.  
  224. /* Discard the temporary file being used to receive a file, if
  225.    appropriate.  */
  226. extern boolean frec_discard_temp P((struct sdaemon *qdaemon,
  227.                     struct stransfer *qtrans));
  228.  
  229. /* Handle data received by a protocol.  This is called by the protocol
  230.    specific routines as data comes in.  The data is passed as two
  231.    buffers because that is convenient for packet based protocols, but
  232.    normally csecond will be 0.  The ilocal argument is the local
  233.    channel number, and the iremote argument is the remote channel
  234.    number.  Either may be -1, if the protocol does not have channels.
  235.    The ipos argument is the position in the file, if the protocol
  236.    knows it; for most protocols, this will be -1.  The fallacked
  237.    argument should be set to TRUE if the remote has acknowledged all
  238.    outstanding data; see uwindow_acked, below, for details. This will
  239.    set *pfexit to TRUE if there is something for the main loop to do.
  240.    A file is complete is when a zero length buffer is passed (cfirst
  241.    == 0).  A command is complete when data containing a null byte is
  242.    passed.  This will return FALSE on error.  If the protocol pfwait
  243.    entry point should exit and let the top level loop continue,
  244.    *pfexit will be set to TRUE (if pfexit is not NULL).  This will not
  245.    set *pfexit to FALSE, so the caller must do that.  */
  246. extern boolean fgot_data P((struct sdaemon *qdaemon,
  247.                 const char *zfirst, size_t cfirst,
  248.                 const char *zsecond, size_t csecond,
  249.                 int ilocal, int iremote,
  250.                 long ipos, boolean fallacked,
  251.                 boolean *pfexit));
  252.  
  253. /* This routine is called when an ack is sent for a file receive.  */
  254. extern void usent_receive_ack P((struct sdaemon *qdaemon,
  255.                  struct stransfer *qtrans));
  256.  
  257. /* A protocol may call this routine to indicate the packets have been
  258.    acknowledged by the remote system.  If the fallacked argument is
  259.    TRUE, then all outstanding packets have been acknowledged; for
  260.    convenience, this may also be indicated by passing fallacked as
  261.    TRUE to fgot_data, above.  Otherwise this routine should be called
  262.    each time a complete window is acked by the remote system.  The
  263.    transfer code uses this information to keep track of when an
  264.    acknowledgement of a file receive has been seen by the other side,
  265.    so that file receives may be handled cleanly if the connection is
  266.    lost.  */
  267. extern void uwindow_acked P((struct sdaemon *qdaemon,
  268.                  boolean fallacked));
  269.